
#include "js/mjs/src/mjs_core.h"
#include "js/mjs/src/mjs_exec.h"
#include "js/mjs/src/mjs_internal.h"
#include "js/mjs/src/mjs_primitive.h"
#include "js/mjs/src/mjs_util.h"

void *my_dlsym(void *handle, const char *name);
void gpio_init(void);
void event_init(void);
void event_pull(void);


int main(void)
{
    mjs_val_t res = MJS_UNDEFINED;
	mjs_err_t err = MJS_OK;

    gpio_init();

    uart_init();

    // event_init();

    struct mjs *mjs = mjs_create();

    mjs_set_ffi_resolver(mjs, my_dlsym);

    err = mjs_exec_file(mjs, "init.js", &res);

    if (err == MJS_OK) {
        mjs_fprintf(res, mjs, stdout);
        putchar('\n');
    } else {
        mjs_print_error(mjs, stdout, NULL, 1 /* print_stack_trace */);
    }

    while(1){
        event_poll(100);
    }

    mjs_destroy(mjs);

    return 0;
}